﻿using System;
using System.Collections;
using System.Collections.Generic;

using AUV5.Model;
using AUV5.DAL.Interface;

namespace AUV5.DAL.Dao
{
    /// <summary>
    /// 功能：     ContactList业务接口的实现
    /// 作者：     lwl
    /// 日期：     2011/10/25
    /// 修改日期： 
    /// 修改人：
    /// 修改内容：
    /// </summary>
    public class ContactListSqlMapDao : BaseSqlMapDao, IContactListDao
    {
        private static ContactListSqlMapDao instance = null;
        private static object syncRoot = new object();

        private ContactListSqlMapDao()
        {
            //
            // TODO: 此处添加ContactListSqlMapDao的构造函数
            //
        }
        public static IContactListDao Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (syncRoot)
                    {
                        if (instance == null)
                        {
                            instance = new ContactListSqlMapDao();
                        }
                    }
                }
                return instance;
            }
        }

        /// <summary>
        /// 得到最大行数
        /// </summary>
        /// <returns></returns>
        public int GetMaxCounts()
        {
            try
            {
                return (int)ExecuteQueryForObject("SelectContactListByMaxCounts", null);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 得到列表
        /// </summary>
        /// <returns></returns>
        public System.Collections.Generic.IList<ContactList> GetList()
        {
            try
            {
                return ExecuteQueryForList<ContactList>("SelectContactList", null);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 通过不同参数得到列表
        /// </summary>
        /// <param name="objParameters"></param>
        /// <returns></returns>
        public System.Collections.Generic.IList<ContactList> GetListByParameters(object objParameters)
        {
            try
            {
                return ExecuteQueryForList<ContactList>("SelectContactListByParameters", objParameters);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 得到明细
        /// </summary>
        /// <param name="ContactID"></param>
        /// <returns></returns>
        public ContactList GetDetail(ContactList contact)
        {
            try
            {
                return ExecuteQueryForObject<ContactList>("SelectContactList", contact) as ContactList;
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 新建
        /// </summary>
        /// <param name="contactlist"></param>
        /// <returns></returns>
        public object Add(ContactList contactlist)
        {
            //int id = GetId("ContactList");
            //contactlist.ContactID = id;

            try
            {
                return ExecuteInsert("InsertContactList", contactlist);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="contactlist"></param>
        /// <returns></returns>
        public int Update(ContactList contactlist)
        {
            try
            {
                return ExecuteUpdate("UpdateContactList", contactlist);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="ContactID"></param>
        /// <returns></returns>
        public int Delete(System.String contactid)
        {
            try
            {
                return ExecuteDelete("DeleteContactList", contactid);
            }
            catch
            {
                throw;
            }
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="contactlist"></param>
        /// <returns></returns>
        public int Delete(ContactList contactlist)
        {
            try 
            {
                return ExecuteDelete("DeleteContactList", contactlist.ContactID);
            }
            catch
            {
                throw;
            }
        }



        /// <summary>
        /// 获取分页数据 
        /// </summary>
        /// <param name="pager"></param>
        /// <returns></returns>
        public IList<ContactList> GetPagedList(NetPager pager)
        { 
            try
            {
                Handler.ContactListHandler handler = new Handler.ContactListHandler();
                ExecuteWithRowDelegate("GetPagedContactList", pager, new IBatisNet.DataMapper.RowDelegate(handler.GetFullList));
                return handler.contactlist;
                //return ExecuteQueryForList<ContactList>("GetPagedContactList", pager);
            }
            catch 
            {
                
                throw;
            }
        }
    }
}
